def p(a):    
    if nm == 1: return False    
    test = True    
    jh = nm - 1    
    while jh > 1:    
        if not nm % jh:    
            test = False                
            break    
        jh -= 1        
    return test   

g = input()  
z = []  
for i in range(len(g)):  
    for jh in range(z + 1,len(g) + 1):  
        nm = int(g[z:jh]) 
        if p(nm):  
            z += [nm]  
print(max(z) if z else 0)
